﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'P_GetEnterprise')
	BEGIN
		DROP  Procedure  [esf_sso].P_GetEnterprise
	END

GO

-- [esf_sso].P_GetEnterprise

CREATE Procedure [esf_sso].P_GetEnterprise
	@pEnterpriseID		INT = NULL
	,@pIdentificationNumber VARCHAR (MAX) = NULL
	,@pIdentificationNumberDigit VARCHAR (MAX) = NULL
	,@pIdentificationTypeCode VARCHAR (MAX) = NULL
AS

	SELECT * FROM [esf_sso].VEnterprise 
	WHERE 
		(@pEnterpriseID IS NULL OR Ent_ID = @pEnterpriseID)
		AND (@pIdentificationNumber IS NULL OR Ent_IdentificationNumber = @pIdentificationNumber)
		AND (@pIdentificationNumberDigit IS NULL OR Ent_IdentificationNumberDigit = @pIdentificationNumberDigit)
		AND (@pIdentificationTypeCode IS NULL OR Ent_IdType_Code = @pIdentificationTypeCode)

GO 
